package at.ac.univie.zsu.aguataplan.util;

import java.text.DecimalFormat;

/**
 * @author gerry
 * 
 */
public class TimeUtil {
	private final static long ONE_SECOND = 1000;
	private final static long SECONDS = 60;
	private final static long MINUTES = 60;
	private final static long HOURS = 24;

	public static String millisToShortDHMS(long duration) {
		String res = "";
		duration /= ONE_SECOND;
		int seconds = (int) (duration % SECONDS);
		duration /= SECONDS;
		int minutes = (int) (duration % MINUTES);
		duration /= MINUTES;
		int hours = (int) (duration % HOURS);
		int days = (int) (duration / HOURS);
		if (days == 0) {
			res = String.format("%02d:%02d:%02d", hours, minutes, seconds);
		} else {
			res = String.format("%dd%02d:%02d:%02d", days, hours, minutes, seconds);
		}
		return res;
	}

	public static String formDouble(float f) {
		DecimalFormat formDouble = new DecimalFormat("######0.0");
		return formDouble.format(f);
	}
}
